package SceneUser2

import (
	"../ProtoGo"
	"../Robot"
	"github.com/golang/protobuf/proto"
)

var command = Cmd.Command_SCENE_USER2_PROTOCMD.Enum()

func RegisterSceneUser2Handler(r *Robot.Robot) {
	r.RobotLog("注册SceneUser2模块")
	//r.Handler.SetModuleBegin()

	pp := Cmd.User2Param_USER2PARAM_PRESETCHATMSG.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handlePresetMsgCmd)

	pp = Cmd.User2Param_USER2PARAM_VAR.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleVarUpdate)

	pp = Cmd.User2Param_USER2PARAM_MENU.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleMenuList)

	pp = Cmd.User2Param_USER2PARAM_NEWDRESSING.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleNewDressing)

	pp = Cmd.User2Param_USER2PARAM_GOTO_LIST.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleGoToListUserCmd)

	pp = Cmd.User2Param_USER2PARAM_QUERYFIGHTERINFO.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleQueryFighterInfo)

	pp = Cmd.User2Param_USER2PARAM_QUERY_MAPAREA.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleQueryMapArea)

	pp = Cmd.User2Param_USER2PARAM_QUERY_ACTION.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleQueryShow)

	pp = Cmd.User2Param_USER2PARAM_QUERY_TRACE_LIST.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleQueryTraceList)

	pp = Cmd.User2Param_USER2PARAM_DOWNLOAD_SCENERY_PHOTO.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleDownloadSceneryPhotoUserCmd)

	pp = Cmd.User2Param_USER2PARAM_UPYUN_AUTHORIZATION.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleUpyunAuthorizationCmd)
}

func handlePresetMsgCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.PresetMsgCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化PresetMsgCmd")
	} else {
		robot.RobotLog("接收协议PresetMsgCmd %s ", response.String())
	}
}

func handleVarUpdate(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.VarUpdate{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化VarUpdate")
	} else {
		robot.RobotLog("接收协议VarUpdate %s ", response.String())
	}
}

func handleMenuList(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.MenuList{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化MenuList")
	} else {
		robot.RobotLog("接收协议MenuList %s ", response.String())
	}
}

func handleNewDressing(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.NewDressing{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化NewDressing")
	} else {
		robot.RobotLog("接收协议NewDressing %s ", response.String())
	}
}

func handleGoToListUserCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.GoToListUserCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化GoToListUserCmd")
	} else {
		robot.RobotLog("接收协议GoToListUserCmd %s ", response.String())
	}
}

func handleQueryFighterInfo(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.QueryFighterInfo{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化QueryFighterInfo")
	} else {
		robot.RobotLog("接收协议QueryFighterInfo %s ", response.String())
	}
}

func handleQueryMapArea(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.QueryMapArea{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化QueryMapArea")
	} else {
		robot.RobotLog("接收协议QueryMapArea %s ", response.String())
	}
}

func handleQueryShow(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.QueryShow{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化QueryShow")
	} else {
		robot.RobotLog("接收协议QueryShow %s ", response.String())
	}
}

func handleQueryTraceList(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.QueryTraceList{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化QueryTraceList")
	} else {
		robot.RobotLog("接收协议QueryTraceList %s ", response.String())
	}
}

func handleDownloadSceneryPhotoUserCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.DownloadSceneryPhotoUserCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化DownloadSceneryPhotoUserCmd")
	} else {
		robot.RobotLog("接收协议DownloadSceneryPhotoUserCmd %s ", response.String())
	}
}

func handleUpyunAuthorizationCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.UpyunAuthorizationCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化UpyunAuthorizationCmd")
	} else {
		robot.RobotLog("接收协议UpyunAuthorizationCmd %s ", response.String())
	}
}
